package com.yangxf.springcloud.controller;

import com.netflix.hystrix.contrib.javanica.annotation.DefaultProperties;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.yangxf.springcloud.service.PaymentHystrixService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@Slf4j
@DefaultProperties(defaultFallback = "pament_global_falbackmethod")
public class OrderHystrixController {

    @Resource
    private PaymentHystrixService paymentHystrixService;

    @GetMapping("/comsumer/payment/hystrix/ok/{id}")
    public String pamentInfo_ok(@PathVariable("id") int id){
        return paymentHystrixService.pamentInfo_ok(id);
    }

    @GetMapping("/comsumer/payment/hystrix/error/{id}")
//    @HystrixCommand(fallbackMethod = "pamentInfo_errorFallBackMethod",commandProperties = {
//        @HystrixProperty(name="execution.isolation.thread.timeoutInMilliseconds",value = "1500")
//    })
    @HystrixCommand
    public String pamentInfo_error(@PathVariable("id") int id){
        int a = 10/0;
        return paymentHystrixService.pamentInfo_error(id);
    }
    public String pamentInfo_errorFallBackMethod(int id){
        return "此处是消费者调用，系统繁忙请稍后o(╥﹏╥)o";
    }

    // 全局降级方法
    public String pament_global_falbackmethod(){
        return "这里是全局降级方法，你的请求方法已经被降级，请稍后再试o(╥﹏╥)o";
    }
}
